#!/usr/bin/env python
# -*- coding: utf-8 -*-

from usermanagement.models import UserProfile
from django.core.mail import send_mass_mail
from celery.task.base import Task

class SendTask(Task):
    def run(self, subject, message):
        accepted_rules_user_profiles = UserProfile.objects.filter(accepted_rules = True)
        mail_adresses = map(lambda x: x.user.email, accepted_rules_user_profiles)
        messages = [(subject, message, 'TomLottermann@googlemail.com', [recipient])
                    for recipient in mail_adresses]
        send_mass_mail(messages)